#include "Bullet.h"

Bullet::Bullet () : mActive (false) //remind Peter to expand on this
{
	
}
Bullet::~Bullet ()
{
	
}

void Bullet::Fire (const SVector2& pos, const SVector2& vel)
{
	mPosition = pos;
	mVelocity = vel;
	mActive = true;
}
void Bullet::Kill ()
{
	mActive = false;
}

void Bullet::Load ()
{
	mSprite.Load ("pokeball.png");		// credits to Rob for the awesome idea
}
void Bullet::Render ()
{
	if (mActive)
	{
		const int width = mSprite.GetWidth ();
		const int height = mSprite.GetHeight ();
		SVector2 offset ((width * 0.5f), (height * 0.5f));
		SVector2 renderPosition = mPosition - offset;

		mSprite.SetPosition (renderPosition);
		mSprite.Render ();
	}
}
void Bullet::Unload ()
{
	mSprite.Unload ();
}
void Bullet::Update (float deltaTime)
{
	if (mActive)
	{
		mPosition += mVelocity * deltaTime;

		const int kWinWidth = IniFile_GetInt ("WinWidth", 800);
		const int kWinHeight = IniFile_GetInt ("WinHeight", 600);
		const int kThreshold = mSprite.GetWidth ();

		if (mPosition.x < -kThreshold || mPosition.x > (kWinWidth + kThreshold) || mPosition.y < -kThreshold ||mPosition.y > (kWinHeight + kThreshold))
		{
			Kill ();
		}
	}
}